
package com.ikamobile.flickrer;

import org.json.JSONException;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.GridView;

import java.io.IOException;
import java.util.List;

public class PhotoGridActivity extends Activity {
    protected static final String LOG_TAG = PhotoGridActivity.class.getSimpleName();
    private GridView mPhotoGrid;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.photo_grid);
        mPhotoGrid = (GridView) findViewById(R.id.photo_grid);

        populate();
    }

    private void populate() {
        try {
            List<Photo> photos = FlickrApi.getPhotosSlow(null);
            ArrayAdapter<Photo> adapter = new ArrayAdapter<Photo>(this, R.layout.photo_item,
                    R.id.title, photos);
            mPhotoGrid.setAdapter(adapter);
        } catch (IOException e) {
            Log.e(LOG_TAG, "failed to download photos.", e);
        } catch (JSONException e) {
            Log.e(LOG_TAG, "failed to download photos.", e);
        }
    }

}
